<template>
  <div class="app-container" ref="appcontainer">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
    <!--  <el-form-item label="充值金额" prop="money">
        <el-input
          v-model="queryParams.money"
          placeholder="请输入充值金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付订单id" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入支付订单id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付对象id" prop="paymentId">
        <el-input
          v-model="queryParams.paymentId"
          placeholder="请输入支付对象id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="请求状态" prop="reqState">
        <el-input
          v-model="queryParams.reqState"
          placeholder="请输入请求状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付状态" prop="payState">
        <el-input
          v-model="queryParams.payState"
          placeholder="请输入支付状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon=""
          size="mini"
          @click="handleAdd"
        >充值</el-button>
      </el-col>
    <!--  <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon=""
          size="mini"
          @click="handleAdd"
          v-hasPermi="['adapayBalancerecharge:adapayBalancerecharge:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['adapayBalancerecharge:adapayBalancerecharge:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['adapayBalancerecharge:adapayBalancerecharge:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['adapayBalancerecharge:adapayBalancerecharge:export']"
          v-if="false"
        >导出</el-button>
      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :height="tableHeight" :data="adapayBalancerechargeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" show-overflow-tooltip />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="充值金额" align="center" prop="money" />
      <el-table-column label="支付订单id" align="center" prop="orderNo" />
      <el-table-column label="支付对象id" align="center" prop="paymentId" />
      <el-table-column label="请求参数" align="center" prop="reqParam" />
      <el-table-column label="回调参数" align="center" prop="resParam" />
      <el-table-column label="请求状态" align="center" prop="reqState" />
      <el-table-column label="请求失败原因" align="center" prop="reqFailMsg" />
      <el-table-column label="异步回调参数" align="center" prop="notifyParam" />
      <el-table-column label="支付状态" align="center" prop="payState" />
      <el-table-column label="支付失败原因" align="center" prop="payFailMsg" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
     <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['adapayBalancerecharge:adapayBalancerecharge:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['adapayBalancerecharge:adapayBalancerecharge:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改余额支付充值记录对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="充值金额" prop="money">
          <el-input v-model="form.money" placeholder="请输入充值金额" />
        </el-form-item>
        <!--<el-form-item label="支付订单id" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入支付订单id" />
        </el-form-item>
        <el-form-item label="支付对象id" prop="paymentId">
          <el-input v-model="form.paymentId" placeholder="请输入支付对象id" />
        </el-form-item>
        <el-form-item label="请求参数" prop="reqParam">
          <el-input v-model="form.reqParam" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="回调参数" prop="resParam">
          <el-input v-model="form.resParam" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="请求状态" prop="reqState">
          <el-input v-model="form.reqState" placeholder="请输入请求状态" />
        </el-form-item>
        <el-form-item label="请求失败原因" prop="reqFailMsg">
          <el-input v-model="form.reqFailMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="异步回调参数" prop="notifyParam">
          <el-input v-model="form.notifyParam" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="支付状态" prop="payState">
          <el-input v-model="form.payState" placeholder="请输入支付状态" />
        </el-form-item>
        <el-form-item label="支付失败原因" prop="payFailMsg">
          <el-input v-model="form.payFailMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="创建来源" prop="createType">
          <el-select v-model="form.createType" placeholder="请选择创建来源">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="更新来源" prop="updateType">
          <el-select v-model="form.updateType" placeholder="请选择更新来源">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>-->
        <ImageScan v-model="form.opinionImages" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAdapayBalancerecharge, getAdapayBalancerecharge, logicDelAdapayBalancerecharge, addAdapayBalancerecharge, updateAdapayBalancerecharge, exportAdapayBalancerecharge } from "@/api/adapayBalancerecharge/adapayBalancerecharge";

export default {
  name: "AdapayBalancerecharge",
  data() {
    return {
      tableHeight:0,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 余额支付充值记录表格数据
      adapayBalancerechargeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        money: null,
        orderNo: null,
        paymentId: null,
        reqParam: null,
        resParam: null,
        reqState: null,
        reqFailMsg: null,
        notifyParam: null,
        payState: null,
        payFailMsg: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.calHeight()
  },
  watch: {
    'showSearch':'calHeight'
  },
  methods: {
    calHeight () {
      this.$nextTick(() => {
        const rect = this.$refs.appcontainer.getBoundingClientRect();
        let height= this.$refs.queryForm.$el.offsetHeight;
        this.tableHeight = rect.height-height-120;
      })
    },
    /** 查询余额支付充值记录列表 */
    getList() {
      this.loading = true;
      listAdapayBalancerecharge(this.queryParams).then(response => {
        this.adapayBalancerechargeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        money: null,
        orderNo: null,
        paymentId: null,
        reqParam: null,
        resParam: null,
        reqState: null,
        reqFailMsg: null,
        notifyParam: null,
        payState: null,
        payFailMsg: null,
        delState: null,
        delUser: null,
        delType: null,
        delTime: null,
        createBy: null,
        createType: null,
        createTime: null,
        updateBy: null,
        updateType: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.showSearch=false;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加余额支付充值记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAdapayBalancerecharge(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改余额支付充值记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {

            addAdapayBalancerecharge(this.form).then(response => {

              debugger
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return logicDelAdapayBalancerecharge(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有余额支付充值记录数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportAdapayBalancerecharge(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
